package cn.xianshu.order.controller;


import cn.xianshu.basic.exception.BasicException;
import cn.xianshu.basic.util.AxiosResult;
import cn.xianshu.order.dto.InsertOrderDto;
import cn.xianshu.order.service.IOrderPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 订单相关
 */
@RestController
@RequestMapping("/order")
public class OrderController {


    @Autowired
    private IOrderPetService orderPetService;

    /**
     * 保存订单
     * @param dto
     * @return
     */
    @PostMapping("/insert")
    public AxiosResult placeOrder(@RequestBody InsertOrderDto dto){
        try {
            String orderNo = orderPetService.placeOrder(dto);
            return AxiosResult.me().setResultObj(orderNo);
        } catch (BasicException e) {
            e.printStackTrace();
            return AxiosResult.me().setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            return AxiosResult.me().setMessage("系统异常!");
        }
    }

}
